home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / devnag.zip / DEVNAG.C < prev    next >
C/C++ Source or Header  |  1991-05-09  |  41KB  |  1,229 lines

  1. /*  devnag.c
  2.     Preprocessor for TeX for texts containing Devanagari characters.
  3.     Copyright (C) 1991  University of Groningen, The Netherlands
  4.  
  5.     Author:   Frans J. Velthuis
  6.     Internet: velthuis@rc.rug.nl
  7.     Bitnet:   velthuis@hgrrug5
  8.  
  9.     This program is free software; you can redistribute it and/or modify
  10.     it under the terms of the GNU General Public License as published by
  11.     the Free Software Foundation; either version 1, or (at your option)
  12.     any later version.
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with this program; if not, write to the Free Software
  21.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23.  
  24. #include <stdio.h>
  25. #include <ctype.h>
  26. #define TRUE 1
  27. #define FALSE 0
  28. #define ill_char  29
  29. #define dummy 30
  30. #define end_of_file 30
  31. #define end_of_line 31
  32. #define n_noligs 40
  33. /* ch_class values */
  34. #define illegal 0
  35. #define cmr 1
  36. #define control 2
  37. #define dn 3
  38. #define numeral 4
  39. /* ch_subclass values */
  40. #define lo_vowel 0
  41. #define hi_vowel 1
  42. #define consonant 2
  43. #define special 3
  44.  
  45. #define LBRACE 273
  46. #define RBRACE 264
  47. #define RE 263
  48. #define RDT 266
  49. #define RN 265
  50. #define RS 256
  51. #define VIRAAM 94
  52.  
  53. short ch_class;
  54. short ch_subclass ;
  55. short join_type;
  56. struct  char_def {
  57.        short ch_typ, ch_subtyp, ch_code, ch_subcode;
  58.      };
  59. struct cons_joins {
  60.        short n_ligs, lig_code;
  61.        short r_type, j_code;
  62.      };
  63. struct ligs {
  64.        char sym_code;
  65.        short sym_new, join_ptr;
  66.        unsigned char in_use;
  67.      };
  68. struct char_def *c_ptr;
  69. struct cons_joins *q_ptr;
  70. char tmp[4];
  71. char string[10];
  72. char wrong[10];
  73. char cstr[2];
  74. FILE *f_in,*f_out,*fopen();
  75. char *p_in,*p_out,*s_ptr,*o_ptr;
  76. char **p_match;
  77. char *strchr();
  78. short i, j, buf_length;
  79. int number;
  80. char symbol;
  81. char com_str[80], prompt[80];
  82. char infil[80], outfil[80];
  83. char inbuf[133], outbuf[133], tmpbuf[133];
  84. char word[500];
  85. char *p;
  86. short syll[30];
  87. int n_halves;
  88. short half_codes[30];
  89. short joincode;
  90. unsigned char dn_yes, hindi_mode, dollar_mode, d_found;
  91. unsigned char no_dn, result, buf_ptr, wait_syl, lin_obey;
  92. unsigned char error, cons_seen, vow_seen, front_r, cmr_mode, num_mode;
  93. short cons_ptr, chr_ptr, cons_code;
  94. short nolig[n_noligs] = {2,3,6,7,16,25,27,34,35,39,40,46,47,49,
  95.     56,58,59,62,65,78,81,82,84,85,86,87,88,89,90,91,92,93,94,95,
  96.     96,98,99,100,101,105};
  97. short ligptrs[105] = {0,1,2,3,4,6,7,9,11,12,13,14,118,16,17,18,
  98.     19,20,21,22,23,24,25,26,27,28,29,
  99.     30,31,32,33,34,35,36,38,39,40,41,
  100.     42,43,44,45,46,47,48,49,50,52,53,119,54,
  101.     55,56,58,59,60,61,62,63,64,65,66,
  102.     68,69,70,71,72,73,74,75,76,77,78,80,
  103.     81,82,84,85,86,87,88,89,90,91,92,93,
  104.     94,95,96,98,99,100,101,102,104,117,105,
  105.     106,107,108,109,110,111,112,113};
  106. struct char_def table[127] = {
  107.     {illegal,special,0,0},                        /* 1 not used */
  108.     {dn,consonant,'\126',34},                     /* 2 .t */
  109.     {dn,consonant,'\130',36},                     /* 3 .d */
  110.     {dn,special,'\72',0},                         /* 4 .o */
  111.     {dn,consonant,'\132',1},                      /* 5 .n */
  112.     {dn,consonant,'\161',2},                      /* 6 .s */
  113.     {dn,lo_vowel,'\33',2},                        /* 7 .r */
  114.     {dn,consonant,'\13',3},                       /* 8 .g */
  115.     {dn,special,'\54',0},                         /* 9 .h */
  116.     {dn,special,'\137',0},                        /* 10 .a */
  117.     {dn,special,'\24',0},                         /* 11 .. */
  118.     {dn,consonant,'\14',4},                       /* 12 .K */
  119.     {dn,consonant,'\127',35},                     /* 13 .T */
  120.     {dn,consonant,'\131',57},                     /* 14 .D */
  121.     {dn,lo_vowel,'\30','\37'},                    /* 15 .l */
  122.     {dn,lo_vowel,'\31','\174'},                   /* 16 .L */
  123.     {dn,lo_vowel,'\21','\16'},                    /* 17 .R */
  124.     {dn,consonant,'\122',32},                     /* 18 "n */
  125.     {dn,consonant,'\146',5},                      /* 19 "s */
  126.     {dn,consonant,'\170',0},                      /* 20 Rh */
  127.     {dn,consonant,'\32',11},                      /* 21 ~n */
  128.     {dn,hi_vowel,267,262},                        /* 22 ~o */
  129.     {dn,hi_vowel,259,4},                          /* 23 ~a */
  130.     {dn,consonant,'\35',31},                      /* 24 ~r */
  131.     {illegal,special,0,0},                        /* 25 not used */
  132.     {illegal,special,0,0},                        /* 26 not used */
  133.     {illegal,special,0,0},                        /* 27 not used */
  134.     {illegal,special,0,0},                        /* 28 not used */
  135.     {illegal,special,0,0},                        /* 29 not used */
  136.     {control,special,0,0},                        /* 30 dummy */
  137.     {control,special,0,0},                        /* 31 end_of_line */
  138.     {control,special,0,0},                        /* 32 space */
  139.     {cmr,special,0,0},                            /* ! */
  140.     {illegal,special,0,0},                        /* " */
  141.     {dn,special,'\25',0},                         /* # */
  142.     {illegal,special,0,0},                        /* $ */
  143.     {illegal,special,0,0},                        /* % */
  144.     {dn,special,0,0},                             /* & */
  145.     {cmr,special,0,0},                            /* ' to - */
  146.     {cmr,special,0,0},                            /* ' to - */
  147.     {cmr,special,0,0},                            /* ' to - */
  148.     {cmr,special,0,0},                            /* ' to - */
  149.     {cmr,special,0,0},                            /* ' to - */
  150.     {cmr,special,0,0},                            /* ' to - */
  151.     {cmr,special,0,0},                            /* ' to - */
  152.     {illegal,special,0,0},                        /* . */
  153.     {dn,special,'\40',0},                         /* / */
  154.     {numeral,special,0,0},                        /* 0 to 9 */
  155.     {numeral,special,0,0},                        /* 0 to 9 */
  156.     {numeral,special,0,0},                        /* 0 to 9 */
  157.     {numeral,special,0,0},                        /* 0 to 9 */
  158.     {numeral,special,0,0},                        /* 0 to 9 */
  159.     {numeral,special,0,0},                        /* 0 to 9 */
  160.     {numeral,special,0,0},                        /* 0 to 9 */
  161.     {numeral,special,0,0},                        /* 0 to 9 */
  162.     {numeral,special,0,0},                        /* 0 to 9 */
  163.     {numeral,special,0,0},                        /* 0 to 9 */
  164.     {cmr,special,0,0},                            /* : and ; */
  165.     {cmr,special,0,0},                            /* : and ; */
  166.     {illegal,special,0,0},                        /* < */
  167.     {cmr,special,0,0},                            /* = */
  168.     {illegal,special,0,0},                        /* > */
  169.     {cmr,special,0,0},                            /* ? */
  170.     {dn,special,'\177',0},                        /* @ */
  171.     {dn,hi_vowel,258,'\101'},                     /* A */
  172.     {dn,consonant,'\102',6},                      /* B */
  173.     {dn,consonant,'\103',33},                     /* C */
  174.     {dn,consonant,'\104',7},                      /* D */
  175.     {dn,hi_vowel,259,'\173'},                     /* E */
  176.     {illegal,special,0,0},                        /* F */
  177.     {dn,consonant,'\107',8},                      /* G */
  178.     {dn,special,'\54',0},                         /* H */
  179.     {dn,hi_vowel,'\111','\106'},                  /* I */
  180.     {dn,consonant,'\112',9},                      /* J */
  181.     {dn,consonant,'\113',10},                     /* K */
  182.     {dn,consonant,'\17',30},                      /* L */
  183.     {dn,special,'\134',0},                        /* M */
  184.     {illegal,special,0,0},                        /* N */
  185.     {dn,hi_vowel,260,'\117'},                     /* O */
  186.     {dn,consonant,'\120',12},                     /* P */
  187.     {illegal,special,0,0},                        /* Q */
  188.     {dn,consonant,'\167',0},